package com.bwie.redkids.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.bwie.redkids.R;
import com.bwie.redkids.bean.HomeListVieweBean;

public class HomeListBaseAdapter extends BaseAdapter implements ListAdapter {

	private Context context;
	private ArrayList<HomeListVieweBean> arrayList;

	public HomeListBaseAdapter(Context context,
			ArrayList<HomeListVieweBean> arrayList) {
		this.context = context;
		this.arrayList = arrayList;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrayList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return arrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.home_list_item, null);
			holder = new ViewHolder();
			holder.iv_home_listImage = (ImageView) convertView
					.findViewById(R.id.iv_home_listImage);
			holder.tv_home_listText = (TextView) convertView
					.findViewById(R.id.tv_home_listText);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.iv_home_listImage.setImageResource(arrayList.get(position)
				.getIv_list_image());
		holder.tv_home_listText.setText(arrayList.get(position)
				.getIv_list_test());
		return convertView;
	}

	class ViewHolder {
		ImageView iv_home_listImage;
		TextView tv_home_listText;
	}

}
